<template>
	<view>
		<view class="u-flex user-box u-p-l-20 u-p-r-20 u-p-b-30 u-p-t-30">
			<view class="u-m-r-10">
				<u-avatar :src="pic" size="140"></u-avatar>
			</view>
			<view class="u-flex-1" @click="toLogin">
				<view class="u-font-18 u-p-b-20 u-p-l-10">{{username}}</view>
				<!-- <view class="u-font-14 u-tips-color">微信号:helang_uView</view> -->
			</view>
			<view class="u-m-l-10 u-p-10">
				<u-icon name="arrow-right" color="#969799" size="28"></u-icon>
			</view>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="account" title="个人信息" @click="toMyInfo"></u-cell-item>
			</u-cell-group>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="star" title="我的预约" @click="toOrder"></u-cell-item>
				<u-cell-item icon="grid" title="我的发布" @click="toPublish"></u-cell-item>
				<u-cell-item icon="car" title="我的车辆" @click="toCar"></u-cell-item>
				<u-cell-item v-if="role == 'admin'" icon="integral" title="审核发布" @click="toAuditing"></u-cell-item>
			</u-cell-group>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="arrow-rightward" title="退出登录" @click='logout'></u-cell-item>
			</u-cell-group>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pic: '',
				username: '',
				show: true,
				role:''
			}
		},
		onShow() {
			let userInfo = this.$store.state.userInfo
			if (userInfo !== '') {
				this.pic = userInfo.avatar
				this.username = userInfo.username
				this.role = userInfo.role
			}else{
				this.username = '请登录'
			}
		},
		methods: {
			toOrder(){
				uni.navigateTo({
					url: '/pages/user/order/order'
				})
			},
			logout(){
				uni.clearStorage()
				uni.navigateTo({
					url: '/pages/user/login/login'
				})
			},
			toAuditing(){
				uni.navigateTo({
					url: '/pages/user/auditing/auditing'
				})
			},
			toMyInfo(){
				uni.navigateTo({
					url: '/pages/user/myInfo/myInfo'
				})
			},
			toPublish(){
				uni.navigateTo({
					url: '/pages/user/publish/myPublish'
				})
			},
			toCar(){
				uni.navigateTo({
					url: '/pages/user/car/car'
				})
			},
			toLogin() {
				if (this.$store.state.userInfo !== '') {
					this.$refs.uToast.show({
						title: '不要重复登录',
						type: 'warning',
					})
				} else {
					uni.navigateTo({
						url: '/pages/user/login/login'
					})
				}
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ededed;
	}

	.camera {
		width: 54px;
		height: 44px;

		&:active {
			background-color: #ededed;
		}
	}

	.user-box {
		background-color: #fff;
	}
</style>
